/**
 * DictParamBuilder.java
 * com.sitech.dmcs.core.param.impl
 * Function： TODO 
 *
 *   ver  author   date    
 * ──────────────────────────────────
 *   	 geutopia  Jan 26, 2011        
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.sitech.timing.param.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.sitech.timing.domain.ParamInfo;
import com.sitech.timing.domain.ParamType;
import com.sitech.timing.domain.ParamValueDict;
import com.sitech.timing.domain.ParamValueDictDetail;
import com.sitech.timing.domain.TaskInstance;
import com.sitech.timing.param.ParamConvert;
import com.sitech.timing.param.ParamService;
import com.sitech.timing.param.ParamValueDictService;



/**
 * ClassName:DictParamBuilder
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   geutopia
 * @version  
 * @since    Ver 1.1
 * @Date	 2011	Jan 26, 2011		11:39:57 AM
 *
 * @see 	 
 */

public class DictParamConvert implements ParamConvert 
{
	
	private ParamValueDictService paramValueDictService;
	private ParamService paramService;
	/**
	 * (non-Javadoc)
	 * @see com.sitech.dmcs.core.param.ParamConvert#Convert(com.sitech.dmcs.core.domain.ParamInfo, com.sitech.dmcs.core.domain.ParamType, com.sitech.dmcs.core.domain.TaskInstance)
	 */
	public Object Convert(ParamInfo paramInfo, ParamType paramType, TaskInstance taskInstance)
	{
		Object object = paramService.produceParamObject(paramType);
		ParamValueDict paramValueDict = paramValueDictService.getParamValueDict(paramInfo.getParamValue());
		
		List<ParamValueDictDetail> paramValueDictDetailList = paramValueDict.getParamValueDictDetaiList();
		if(paramValueDictDetailList != null && paramValueDictDetailList.size() > 0)
		{
			Map<String, String> paramValueMap = new HashMap<String, String>();
			
			for(ParamValueDictDetail paramValueDictDetail : paramValueDictDetailList)
			{
				paramValueMap.put(paramValueDictDetail.getParamName(), paramValueDictDetail.getParamValue());
			}
			try
			{
				BeanUtils.populate(object, paramValueMap);
			}
			catch (IllegalAccessException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			catch (InvocationTargetException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return object;
	}
	public ParamValueDictService getParamValueDictService()
	{
		return paramValueDictService;
	}
	public void setParamValueDictService(ParamValueDictService paramValueDictService)
	{
		this.paramValueDictService = paramValueDictService;
	}
	public ParamService getParamService()
	{
		return paramService;
	}
	public void setParamService(ParamService paramService)
	{
		this.paramService = paramService;
	}

}
